package com.ruoyi.common.core.domain.dto;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.enums.UserEventType;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;

/**
 * Description:
 * Author: YangShiWei
 * Email: strongwalter2014@gmail.com
 * Datetime: 2023/2/16 10:09
 */
@Data
@NoArgsConstructor
public class EventPlan implements Serializable {

    public String getRangeStr() {
        return DateUtil.format(startDate, DatePattern.NORM_DATE_PATTERN) + " ~ " + DateUtil.format(endDate, DatePattern.NORM_DATE_PATTERN);
    }

    public EventPlan(Date startDate, Date endDate, UserEventType type) {
        this.startDate = startDate;
        this.endDate = endDate;
        this.type = type;
    }

    /**
     * 应检测开始日期
     */

    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date startDate;

    /**
     * 应检测结束日期
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date endDate;

    /**
     * 事件类型
     */
    private UserEventType type;

    /**
     * 实际发生事件记录ID
     */
    private Long eventId;

    /**
     * 事件实际发生日期时间，为空则代表未进行
     */
    private Date eventDate;

    /**
     * 判断给定事件日期是否发生在该计划周期内
     *
     * @param eventDate
     * @return
     */
    public boolean isOccurInThisPlanCycle(Date eventDate) {
        if (eventDate == null) return false;
        return eventDate.after(startDate) && eventDate.before(endDate);
    }

}
